(function() {
  'use strict';

  angular
    .module('client')
    .directive('remoteNavbar', remoteNavbar);

  remoteNavbar.$inject = [];
  function remoteNavbar() {
    var directive = {
      restrict: 'E',
      templateUrl: 'app/components/navbar/navbar.html',
      controller: RemoteNavbarController,
      controllerAs: 'navCtrl',
      binToController: true,
      replace: true,
    };
    return directive;

    RemoteNavbarController.$inject = ['AuthService', '$state', '$stateParams', 'navbarService'];
    function RemoteNavbarController(AuthService, $state, $stateParams, navbarService) {
      var vm  = this;
      vm.logout = logout;

      function logout() {
        if ($stateParams.deviceID) {
          navbarService.releaseDevice($stateParams.deviceID)
            .then(function (resp) {
              AuthService.logout();
            })
        } else {
          AuthService.logout();
        }
      }

    }
  }
})();
